home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / gepackte_disketten / 1994 / 08_94_5.dms / 08_94_5.adf / term-4.0-Source.lha / termSerial.c < prev    next >
C/C++ Source or Header  |  1994-07-07  |  43KB  |  2,210 lines

  1. /*
  2. **    termSerial.c
  3. **
  4. **    Serial driver support routines
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* The quantum of bytes to be read from the serial port,
  13.      * to be fed to the terminal emulation monster. This is where
  14.      * two worlds collide; first there is the idea to process as
  15.      * much data as there is currently available for reasons
  16.      * of efficiency. Second there is a problem caused by the
  17.      * fact that terminal emulation may not be able to
  18.      * output text as fast as new data comes in. Terminal and
  19.      * serial input will be blocked until all data is processed,
  20.      * so the quantum should be pretty small to avoid unnecessary
  21.      * processing delays.
  22.      */
  23.  
  24.     /* Local copy of serial driver name and unit number. */
  25.  
  26. STATIC UBYTE __far    SerialDevice[40];
  27. STATIC LONG        UnitNumber = -1;
  28.  
  29. STATIC BOOLEAN        SerialLocked = FALSE;
  30.  
  31.     /* SendBreak():
  32.      *
  33.      *    Transmit a break signal.
  34.      */
  35.  
  36. VOID
  37. SendBreak()
  38. {
  39.     if(WriteRequest)
  40.     {
  41.         BYTE OldStatus = Status;
  42.  
  43.         Status = STATUS_BREAKING;
  44.  
  45.         WriteRequest -> IOSer . io_Command = SDCMD_BREAK;
  46.  
  47.         DoIO(WriteRequest);
  48.  
  49.         Status = OldStatus;
  50.     }
  51. }
  52.  
  53.     /* HangUp():
  54.      *
  55.      *    Hang up the line.
  56.      */
  57.  
  58. VOID
  59. HangUp()
  60. {
  61.     if(WriteRequest)
  62.     {
  63.         BYTE OldStatus = Status;
  64.  
  65.         Status = STATUS_HANGUP;
  66.  
  67.             /* Are we to drop the DTR line
  68.              * before sending the hangup
  69.              * string?
  70.              */
  71.  
  72.         if(Config -> ModemConfig -> DropDTR)
  73.         {
  74.             /* Let's be nice and try to transmit the
  75.              * `drop the line' command before
  76.              * trying to close and reopen the driver.
  77.              */
  78.  
  79.             WriteRequest -> IOSer . io_Command    = SIOCMD_SETCTRLLINES;
  80.             WriteRequest -> IOSer . io_Offset    = SIOB_DTRF;
  81.             WriteRequest -> IOSer . io_Length    = 0;
  82.  
  83.                 /* Transmit the command. */
  84.  
  85.             if(!DoIO(WriteRequest))
  86.             {
  87.                     /* Wait a bit... */
  88.  
  89.                 WaitTime(1,0);
  90.  
  91.                     /* Raise the line again. */
  92.  
  93.                 WriteRequest -> IOSer . io_Command    = SIOCMD_SETCTRLLINES;
  94.                 WriteRequest -> IOSer . io_Offset    = SIOB_DTRF;
  95.                 WriteRequest -> IOSer . io_Length    = SIOB_DTRF;
  96.  
  97.                 DoIO(WriteRequest);
  98.             }
  99.             else
  100.             {
  101.                     /* Do it the standard way: close and reopen
  102.                      * the serial driver (the serial.device is
  103.                      * supposed to drop the DTR line when closed).
  104.                      */
  105.  
  106.                 if(!DropDTR())
  107.                 {
  108.                     if(!MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_REOPEN_UNIT_TXT),LocaleString(MSG_TERMMAIN_IGNORE_QUIT_TXT),Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber))
  109.                         MainTerminated = TRUE;
  110.                 }
  111.             }
  112.         }
  113.  
  114.             /* Transmit the hangup command. */
  115.  
  116.         if(Config -> ModemConfig -> ModemHangup[0])
  117.             SerialCommand(Config -> ModemConfig -> ModemHangup);
  118.  
  119.             /* Reset to old status. */
  120.  
  121.         Status = OldStatus;
  122.     }
  123. }
  124.  
  125.     /* SetFlags(struct IOExtSer *SomeRequest):
  126.      *
  127.      *    Set the contents of a serial device request according
  128.      *    to the current configuration settings.
  129.      */
  130.  
  131. VOID __regargs
  132. SetFlags(struct IOExtSer *SomeRequest)
  133. {
  134.         /* Remember new baud rate. */
  135.  
  136.     DTERate = Config -> SerialConfig -> BaudRate;
  137.  
  138.     SomeRequest -> io_Baud        = Config -> SerialConfig -> BaudRate;
  139.     SomeRequest -> io_BrkTime    = Config -> SerialConfig -> BreakLength;
  140.     SomeRequest -> io_ReadLen    = Config -> SerialConfig -> BitsPerChar;
  141.     SomeRequest -> io_WriteLen    = Config -> SerialConfig -> BitsPerChar;
  142.     SomeRequest -> io_StopBits    = Config -> SerialConfig -> StopBits;
  143.     SomeRequest -> io_RBufLen    = Config -> SerialConfig -> SerialBufferSize;
  144.  
  145.     SomeRequest -> io_ExtFlags    &= ~(SEXTF_MSPON | SEXTF_MARK);
  146.     SomeRequest -> io_SerFlags    &= ~(SERF_PARTY_ON | SERF_PARTY_ODD | SERF_7WIRE | SERF_RAD_BOOGIE);
  147.  
  148.     switch(Config -> SerialConfig -> Parity)
  149.     {
  150.         case PARITY_EVEN:
  151.  
  152.             SomeRequest -> io_SerFlags |= SERF_PARTY_ON;
  153.             break;
  154.  
  155.         case PARITY_ODD:
  156.  
  157.             SomeRequest -> io_SerFlags |= SERF_PARTY_ON | SERF_PARTY_ODD;
  158.             break;
  159.  
  160.         case PARITY_MARK:
  161.  
  162.             SomeRequest -> io_SerFlags |= SERF_PARTY_ON;
  163.             SomeRequest -> io_ExtFlags |= SEXTF_MSPON | SEXTF_MARK;
  164.             break;
  165.  
  166.         case PARITY_SPACE:
  167.  
  168.             SomeRequest -> io_SerFlags |= SERF_PARTY_ON;
  169.             SomeRequest -> io_ExtFlags |= SEXTF_MSPON;
  170.             break;
  171.     }
  172.  
  173.     if(Config -> SerialConfig -> HandshakingProtocol != HANDSHAKING_NONE)
  174.         SomeRequest -> io_SerFlags |= SERF_7WIRE;
  175.  
  176.     if(Config -> SerialConfig -> HighSpeed)
  177.         SomeRequest -> io_SerFlags |= SERF_RAD_BOOGIE;
  178.  
  179.     if(Config -> SerialConfig -> Shared)
  180.         SomeRequest -> io_SerFlags |= SERF_SHARED;
  181.  
  182.     SomeRequest -> io_SerFlags |= SERF_XDISABLED;
  183. }
  184.  
  185.     /* GetFlags(struct Configuration *Config,struct IOExtSer *SomeRequest):
  186.      *
  187.      *    Update configuration with serial settings.
  188.      */
  189.  
  190. VOID __regargs
  191. GetFlags(struct Configuration *Config,struct IOExtSer *SomeRequest)
  192. {
  193.     Config -> SerialConfig -> BaudRate    = SomeRequest -> io_Baud;
  194.     Config -> SerialConfig -> BreakLength    = SomeRequest -> io_BrkTime;
  195.     Config -> SerialConfig -> BitsPerChar    = SomeRequest -> io_ReadLen;
  196.     Config -> SerialConfig -> BitsPerChar    = SomeRequest -> io_WriteLen;
  197.     Config -> SerialConfig -> StopBits    = SomeRequest -> io_StopBits;
  198.  
  199.     if(SomeRequest -> io_SerFlags & SERF_PARTY_ON)
  200.     {
  201.         if(SomeRequest -> io_SerFlags & SERF_PARTY_ODD)
  202.             Config -> SerialConfig -> Parity = PARITY_ODD;
  203.         else
  204.         {
  205.             if(SomeRequest -> io_ExtFlags & SEXTF_MSPON)
  206.             {
  207.                 if(SomeRequest -> io_ExtFlags & SEXTF_MARK)
  208.                     Config -> SerialConfig -> Parity = PARITY_MARK;
  209.                 else
  210.                     Config -> SerialConfig -> Parity = PARITY_SPACE;
  211.             }
  212.         }
  213.     }
  214.     else
  215.         Config -> SerialConfig -> Parity = PARITY_NONE;
  216.  
  217.     if(SomeRequest -> io_SerFlags & SERF_7WIRE)
  218.         Config -> SerialConfig -> HandshakingProtocol = HANDSHAKING_RTSCTS;
  219.     else
  220.         Config -> SerialConfig -> HandshakingProtocol = HANDSHAKING_NONE;
  221.  
  222.     if(SomeRequest -> io_SerFlags & SERF_RAD_BOOGIE)
  223.         Config -> SerialConfig -> HighSpeed = TRUE;
  224.     else
  225.         Config -> SerialConfig -> HighSpeed = FALSE;
  226.  
  227.     if(SomeRequest -> io_SerFlags & SERF_SHARED)
  228.         Config -> SerialConfig -> Shared = TRUE;
  229.     else
  230.         Config -> SerialConfig -> Shared = FALSE;
  231.  
  232.     SomeRequest -> io_SerFlags |= SERF_XDISABLED;
  233. }
  234.  
  235.     /* CallMenu(STRPTR Name,ULONG Code):
  236.      *
  237.      *    Call a menu function either through the name of the corresponding
  238.      *    menu item or a menu number.
  239.      */
  240.  
  241. STATIC VOID __inline
  242. CallMenu(STRPTR Name,ULONG Code)
  243. {
  244.     WORD MenuNum = -1,Item = 0,Sub = 0,i;
  245.  
  246.         /* Are we to look for a name? */
  247.  
  248.     if(Name)
  249.     {
  250.         WORD Len = strlen(Name);
  251.  
  252.             /* Scan the menu list... */
  253.  
  254.         for(i = 0 ; TermMenu[i] . nm_Type != NM_END ; i++)
  255.         {
  256.             switch(TermMenu[i] . nm_Type)
  257.             {
  258.                 case NM_TITLE:
  259.  
  260.                     MenuNum++;
  261.                     Item = Sub = 0;
  262.                     break;
  263.  
  264.                 case NM_ITEM:
  265.  
  266.                     Sub = 0;
  267.                     break;
  268.             }
  269.  
  270.                 /* Did we get a valid name string? */
  271.  
  272.             if(TermMenu[i] . nm_Label != NM_BARLABEL)
  273.             {
  274.                     /* Does the name match our template? */
  275.  
  276.                 if(!Strnicmp(TermMenu[i] . nm_Label,Name,Len))
  277.                 {
  278.                     struct MenuItem *MenuItem = ItemAddress(Menu,FULLMENUNUM(MenuNum,Item,Sub));
  279.  
  280.                     if(MenuItem)
  281.                         HandleMenuCode((ULONG)TermMenu[i] . nm_UserData,NULL);
  282.  
  283.                     break;
  284.                 }
  285.             }
  286.  
  287.             switch(TermMenu[i] . nm_Type)
  288.             {
  289.                 case NM_ITEM:
  290.  
  291.                     Item++;
  292.                     break;
  293.  
  294.                 case NM_SUB:
  295.  
  296.                     Sub++;
  297.                     break;
  298.             }
  299.         }
  300.     }
  301.     else
  302.     {
  303.         WORD    TheMenu    =  Code % 100,
  304.             TheItem    = (Code / 100) % 100,
  305.             TheSub    =  Code / 10000;
  306.  
  307.             /* Scan the menu list... */
  308.  
  309.         for(i = 0 ; TermMenu[i] . nm_Type != NM_END ; i++)
  310.         {
  311.             switch(TermMenu[i] . nm_Type)
  312.             {
  313.                 case NM_TITLE:
  314.  
  315.                     MenuNum++;
  316.                     Item = Sub = 0;
  317.                     break;
  318.  
  319.                 case NM_ITEM:
  320.  
  321.                     Sub = 0;
  322.                     break;
  323.             }
  324.  
  325.                 /* Is it the menu number we want? */
  326.  
  327.             if(TheMenu == MenuNum && TheItem == Item && TheSub == Sub)
  328.             {
  329.                 if(TermMenu[i] . nm_Label != NM_BARLABEL)
  330.                 {
  331.                     struct MenuItem *MenuItem = ItemAddress(Menu,FULLMENUNUM(MenuNum,Item,Sub));
  332.  
  333.                     if(MenuItem)
  334.                         HandleMenuCode((ULONG)TermMenu[i] . nm_UserData,NULL);
  335.                 }
  336.  
  337.                 break;
  338.             }
  339.  
  340.             switch(TermMenu[i] . nm_Type)
  341.             {
  342.                 case NM_ITEM:
  343.  
  344.                     Item++;
  345.                     break;
  346.  
  347.                 case NM_SUB:
  348.  
  349.                     Sub++;
  350.                     break;
  351.             }
  352.         }
  353.     }
  354. }
  355.  
  356.     /* SerialCommand(STRPTR String):
  357.      *
  358.      *    Send a command string to the serial line and
  359.      *    interprete the control sequences.
  360.      */
  361.  
  362. VOID __regargs
  363. SerialCommand(STRPTR String)
  364. {
  365.     BYTE    (*  SendLineLocal)(register STRPTR,register LONG);
  366.  
  367.     LONG    Count = 0,i,Len = strlen(String);
  368.  
  369.     BYTE    GotControl    = FALSE,
  370.         GotEscape    = FALSE;
  371.  
  372.     SendLineLocal = SendLine;
  373.  
  374.         /* Scan the string. */
  375.  
  376.     for(i = 0 ; i < Len ; i++)
  377.     {
  378.             /* We are looking for plain characters
  379.              * and the control ('\') and escape
  380.              * ('^') characters.
  381.              */
  382.  
  383.         if(!GotControl && !GotEscape)
  384.         {
  385.                 /* Got a control character,
  386.                  * the next byte will probably be
  387.                  * a command sequence.
  388.                  */
  389.  
  390.             if(String[i] == '\\')
  391.             {
  392.                 GotControl = TRUE;
  393.                 continue;
  394.             }
  395.  
  396.                 /* Got an escape character,
  397.                  * the next byte will be some
  398.                  * kind of control character
  399.                  * (such as XON, XOF, bell, etc.).
  400.                  */
  401.  
  402.             if(String[i] == '^')
  403.             {
  404.                 GotEscape = TRUE;
  405.                 continue;
  406.             }
  407.  
  408.                 /* This tells us to wait another
  409.                  * second before continuing with
  410.                  * the scanning.
  411.                  */
  412.  
  413.             if(String[i] == '~')
  414.             {
  415.                 if(Count)
  416.                 {
  417.                     (*SendLineLocal)(SharedBuffer,Count);
  418.  
  419.                     Count = 0;
  420.                 }
  421.  
  422.                 WaitTime(0,MILLION / 2);
  423.  
  424.                 HandleSerial();
  425.  
  426.                 continue;
  427.             }
  428.  
  429.                 /* Stuff the character into the
  430.                  * buffer.
  431.                  */
  432.  
  433.             SharedBuffer[Count++] = String[i];
  434.         }
  435.         else
  436.         {
  437.                 /* Convert the character to a control
  438.                  * style character (^C, etc.).
  439.                  */
  440.  
  441.             if(GotEscape)
  442.             {
  443.                 if(ToUpper(String[i]) >= 'A' && ToUpper(String[i]) <= '_')
  444.                     SharedBuffer[Count++] = ToUpper(String[i]) - '@';
  445.                 else
  446.                     SharedBuffer[Count++] = String[i];
  447.  
  448.                 GotEscape = FALSE;
  449.             }
  450.  
  451.                 /* The next character represents a command. */
  452.  
  453.             if(GotControl)
  454.             {
  455.                 switch(ToUpper(String[i]))
  456.                 {
  457.                         /* Fall back to default send mode. */
  458.  
  459.                     case '0':
  460.  
  461.                         if(Count)
  462.                         {
  463.                             (*SendLineLocal)(SharedBuffer,Count);
  464.  
  465.                             Count = 0;
  466.                         }
  467.  
  468.                         SendLineLocal = SendLine;
  469.                         break;
  470.  
  471.                         /* Select `direct' send mode. */
  472.  
  473.                     case '1':
  474.  
  475.                         if(Count)
  476.                         {
  477.                             (*SendLineLocal)(SharedBuffer,Count);
  478.  
  479.                             Count = 0;
  480.                         }
  481.  
  482.                         SendLineLocal = SendLineSimple;
  483.                         break;
  484.  
  485.                         /* Select `echo' send mode. */
  486.  
  487.                     case '2':
  488.  
  489.                         if(Count)
  490.                         {
  491.                             (*SendLineLocal)(SharedBuffer,Count);
  492.  
  493.                             Count = 0;
  494.                         }
  495.  
  496.                         if(Config -> ClipConfig -> SendTimeout)
  497.                             SendLineLocal = SendLineEcho;
  498.                         else
  499.                             SendLineLocal = SendLineSimple;
  500.  
  501.                         break;
  502.  
  503.                         /* Select `any echo' send mode. */
  504.  
  505.                     case '3':
  506.  
  507.                         if(Count)
  508.                         {
  509.                             (*SendLineLocal)(SharedBuffer,Count);
  510.  
  511.                             Count = 0;
  512.                         }
  513.  
  514.                         if(Config -> ClipConfig -> SendTimeout)
  515.                             SendLineLocal = SendLineAnyEcho;
  516.                         else
  517.                             SendLineLocal = SendLineSimple;
  518.  
  519.                         break;
  520.  
  521.                         /* Select `prompt' send mode. */
  522.  
  523.                     case '4':
  524.  
  525.                         if(Count)
  526.                         {
  527.                             (*SendLineLocal)(SharedBuffer,Count);
  528.  
  529.                             Count = 0;
  530.                         }
  531.  
  532.                         if(Config -> ClipConfig -> SendTimeout)
  533.                             SendLineLocal = SendLinePrompt;
  534.                         else
  535.                             SendLineLocal = SendLineSimple;
  536.  
  537.                         break;
  538.  
  539.                         /* Select `delay' send mode. */
  540.  
  541.                     case '5':
  542.  
  543.                         if(Count)
  544.                         {
  545.                             (*SendLineLocal)(SharedBuffer,Count);
  546.  
  547.                             Count = 0;
  548.                         }
  549.  
  550.                         if(Config -> ClipConfig -> LineDelay || Config -> ClipConfig -> CharDelay)
  551.                             SendLineLocal = SendLineDelay;
  552.                         else
  553.                             SendLineLocal = SendLineSimple;
  554.  
  555.                         break;
  556.  
  557.                         /* Select `keyboard' send mode. */
  558.  
  559.                     case '6':
  560.  
  561.                         if(Count)
  562.                         {
  563.                             (*SendLineLocal)(SharedBuffer,Count);
  564.  
  565.                             Count = 0;
  566.                         }
  567.  
  568.                         SendLineLocal = SendLineKeyDelay;
  569.                         break;
  570.  
  571.                         /* Translate code. */
  572.  
  573.                     case '*':
  574.  
  575.                         i++;
  576.  
  577.                         while(i < Len && String[i] == ' ')
  578.                             i++;
  579.  
  580.                         if(i < Len)
  581.                         {
  582.                             UBYTE DummyBuffer[5],j = 0,Char;
  583.  
  584.                             if(String[i] >= '0' && String[i] <= '9')
  585.                             {
  586.                                 while(j < 3 && i < Len)
  587.                                 {
  588.                                     Char = String[i++];
  589.  
  590.                                     if(Char >= '0' && Char <= '9')
  591.                                         DummyBuffer[j++] = Char;
  592.                                     else
  593.                                     {
  594.                                         i--;
  595.  
  596.                                         break;
  597.                                     }
  598.                                 }
  599.                             }
  600.                             else
  601.                             {
  602.                                 while(j < 4 && i < Len)
  603.                                 {
  604.                                     Char = ToLower(String[i++]);
  605.  
  606.                                     if((Char >= '0' && Char <= '9') || (Char >= 'a' && Char <= 'z'))
  607.                                         DummyBuffer[j++] = Char;
  608.                                     else
  609.                                     {
  610.                                         i--;
  611.  
  612.                                         break;
  613.                                     }
  614.                                 }
  615.                             }
  616.  
  617.                             DummyBuffer[j] = 0;
  618.  
  619.                             SharedBuffer[Count++] = NameToCode(DummyBuffer);
  620.                         }
  621.  
  622.                         i--;
  623.  
  624.                         break;
  625.  
  626.                         /* Execute an AmigaDOS command. */
  627.  
  628.                     case 'D':
  629.  
  630.                         if(!InRexx)
  631.                         {
  632.                             if(!WeAreBlocking)
  633.                             {
  634.                                 BlockWindows();
  635.  
  636.                                 SendAmigaDOSCommand(&String[i + 1]);
  637.  
  638.                                 ReleaseWindows();
  639.                             }
  640.                             else
  641.                                 SendAmigaDOSCommand(&String[i + 1]);
  642.                         }
  643.  
  644.                         return;
  645.  
  646.                         /* Execute an ARexx command. */
  647.  
  648.                     case 'A':
  649.  
  650.                         if(!InRexx)
  651.                         {
  652.                             if(!WeAreBlocking)
  653.                             {
  654.                                 BlockWindows();
  655.  
  656.                                 SendARexxCommand(&String[i + 1]);
  657.  
  658.                                 ReleaseWindows();
  659.                             }
  660.                             else
  661.                                 SendARexxCommand(&String[i + 1]);
  662.                         }
  663.  
  664.                         return;
  665.  
  666.                         /* Add the control character ('\'). */
  667.  
  668.                     case '\\':
  669.  
  670.                         SharedBuffer[Count++] = '\\';
  671.                         break;
  672.  
  673.                         /* This is a backspace. */
  674.  
  675.                     case 'B':
  676.  
  677.                         SharedBuffer[Count++] = '\b';
  678.                         break;
  679.  
  680.                         /* This is a form feed. */
  681.  
  682.                     case 'F':
  683.  
  684.                         SharedBuffer[Count++] = '\f';
  685.                         break;
  686.  
  687.                         /* This is a line feed. */
  688.  
  689.                     case 'N':
  690.  
  691.                         SharedBuffer[Count++] = '\n';
  692.                         break;
  693.  
  694.                         /* Send the current password. */
  695.  
  696.                     case 'P':
  697.  
  698.                         if(Password[0])
  699.                         {
  700.                             if(Count)
  701.                             {
  702.                                 (*SendLineLocal)(SharedBuffer,Count);
  703.  
  704.                                 Count = 0;
  705.                             }
  706.  
  707.                             (*SendLineLocal)(Password,strlen(Password));
  708.                         }
  709.  
  710.                         break;
  711.  
  712.                         /* This is a carriage return. */
  713.  
  714.                     case 'R':
  715.  
  716.                         SharedBuffer[Count++] = '\r';
  717.                         break;
  718.  
  719.                         /* This is a tab. */
  720.  
  721.                     case 'T':
  722.  
  723.                         SharedBuffer[Count++] = '\t';
  724.                         break;
  725.  
  726.                         /* Send the current user name. */
  727.  
  728.                     case 'U':
  729.  
  730.                         if(UserName[0])
  731.                         {
  732.                             if(Count)
  733.                             {
  734.                                 (*SendLineLocal)(SharedBuffer,Count);
  735.  
  736.                                 Count = 0;
  737.                             }
  738.  
  739.                             (*SendLineLocal)(UserName,strlen(UserName));
  740.                         }
  741.  
  742.                         break;
  743.  
  744.                         /* Send a break across the serial line. */
  745.  
  746.                     case 'X':
  747.  
  748.                         if(Count)
  749.                         {
  750.                             (*SendLineLocal)(SharedBuffer,Count);
  751.  
  752.                             Count = 0;
  753.                         }
  754.  
  755.                         SendBreak();
  756.  
  757.                         break;
  758.  
  759.                         /* Feed the contents of the
  760.                          * clipboard into the input
  761.                          * stream.
  762.                          */
  763.  
  764.                     case 'I':
  765.  
  766.                         if(Count)
  767.                             (*SendLineLocal)(SharedBuffer,Count);
  768.  
  769.                         Count = LoadClip(SharedBuffer,256);
  770.  
  771.                         break;
  772.  
  773.                         /* Send a string to the clipboard. */
  774.  
  775.                     case 'G':
  776.  
  777.                         if(String[i + 1])
  778.                             SaveClip(&String[i + 1],strlen(&String[i + 1]));
  779.  
  780.                         return;
  781.  
  782.                         /* Send a string to the clipboard. */
  783.  
  784.                     case 'H':
  785.  
  786.                         if(String[i + 1])
  787.                             AddClip(&String[i + 1],strlen(&String[i + 1]));
  788.  
  789.                         return;
  790.  
  791.                         /* Produce the escape character. */
  792.  
  793.                     case 'E':
  794.  
  795.                         SharedBuffer[Count++] = ESC;
  796.                         break;
  797.  
  798.                         /* Call a menu item. */
  799.  
  800.                     case 'C':
  801.  
  802.                         i++;
  803.  
  804.                             /* Scan for a menu number or
  805.                              * a single quote...
  806.                              */
  807.  
  808.                         while(i < Len)
  809.                         {
  810.                             if(String[i] >= '0' && String[i] <= '9')
  811.                                 break;
  812.  
  813.                             if(String[i] == '\'')
  814.                                 break;
  815.  
  816.                             if(String[i] != ' ')
  817.                                 break;
  818.  
  819.                             i++;
  820.                         }
  821.  
  822.                         if(i < Len)
  823.                         {
  824.                             UBYTE DummyBuffer[256];
  825.  
  826.                                 /* Did we get a quote? */
  827.  
  828.                             if(String[i] == '\'')
  829.                             {
  830.                                 LONG Start = ++i;
  831.  
  832.                                 if(String[Start])
  833.                                 {
  834.                                     WORD Length;
  835.  
  836.                                     while(i < Len)
  837.                                     {
  838.                                         if(String[i] != '\'')
  839.                                             i++;
  840.                                         else
  841.                                             break;
  842.                                     }
  843.  
  844.                                     if(String[i] == '\'')
  845.                                         Length = i - Start;
  846.                                     else
  847.                                         Length = i - Start + 1;
  848.  
  849.                                     memcpy(DummyBuffer,&String[Start],Length);
  850.  
  851.                                     DummyBuffer[Length] = 0;
  852.  
  853.                                     CallMenu(DummyBuffer,0);
  854.                                 }
  855.                             }
  856.                             else
  857.                             {
  858.                                 if(String[i] >= '0' && String[i] <= '9')
  859.                                 {
  860.                                     LONG Start = i,Length;
  861.  
  862.                                     while(i < Len)
  863.                                     {
  864.                                         if(String[i] >= '0' && String[i] <= '9')
  865.                                             i++;
  866.                                         else
  867.                                             break;
  868.                                     }
  869.  
  870.                                     if(i == Start)
  871.                                         Length = 1;
  872.                                     else
  873.                                         Length = i - Start;
  874.  
  875.                                     memcpy(DummyBuffer,&String[Start],Length);
  876.  
  877.                                     DummyBuffer[Length] = 0;
  878.  
  879.                                     CallMenu(NULL,Atol(DummyBuffer));
  880.                                 }
  881.                             }
  882.                         }
  883.  
  884.                         break;
  885.  
  886.                         /* Stuff the character into the buffer. */
  887.  
  888.                     default:
  889.  
  890.                         SharedBuffer[Count++] = String[i];
  891.                         break;
  892.                 }
  893.  
  894.                 GotControl = FALSE;
  895.             }
  896.         }
  897.  
  898.             /* If the buffer is full, release it. */
  899.  
  900.         if(Count == 256)
  901.         {
  902.             (*SendLineLocal)(SharedBuffer,Count);
  903.  
  904.             Count = 0;
  905.         }
  906.     }
  907.  
  908.     if(Count)
  909.         (*SendLineLocal)(SharedBuffer,Count);
  910. }
  911.  
  912.     /* SerWriteVerbatim(APTR Buffer,LONG Size,BOOLEAN Echo):
  913.      *
  914.      *    The `no fancy features' version of SerWrite().
  915.      */
  916.  
  917. VOID __regargs
  918. SerWriteVerbatim(APTR Buffer,LONG Size,BOOLEAN Echo)
  919. {
  920.     if(XProtocolBase && (TransferBits & XPRS_USERMON))
  921.         Size = XProtocolUserMon(XprIO,Buffer,Size,Size);
  922.  
  923.     if(Size > 0)
  924.     {
  925.         WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  926.         WriteRequest -> IOSer . io_Data        = Buffer;
  927.         WriteRequest -> IOSer . io_Length    = Size;
  928.  
  929.         if(Echo)
  930.         {
  931.             if(Marking)
  932.                 DropMarker();
  933.  
  934.             SendIO(WriteRequest);
  935.  
  936.             ConProcess(Buffer,Size);
  937.  
  938.             WaitIO(WriteRequest);
  939.         }
  940.         else
  941.             DoIO(WriteRequest);
  942.  
  943.         BytesOut += Size;
  944.     }
  945. }
  946.  
  947.     /* SerWrite(APTR Buffer,LONG Size):
  948.      *
  949.      *    Send a number of bytes across the serial line.
  950.      */
  951.  
  952. VOID __regargs
  953. SerWrite(APTR Buffer,LONG Size)
  954. {
  955.     if(Size < 0)
  956.         Size = strlen(Buffer);
  957.  
  958.     if(Size)
  959.     {
  960.         if(RememberInput)
  961.         {
  962.             RememberInputText(Buffer,Size);
  963.  
  964.             if(((UBYTE *)Buffer)[Size - 1] == '\r' && RecordingLine)
  965.             {
  966.                 RememberSpill();
  967.  
  968.                 RecordingLine = FALSE;
  969.  
  970.                 RememberOutput = TRUE;
  971.                 RememberInput = FALSE;
  972.  
  973.                 CheckItem(MEN_RECORD_LINE,FALSE);
  974.             }
  975.         }
  976.         else
  977.         {
  978.             if(RememberOutput)
  979.             {
  980.                 RememberInputText(Buffer,Size);
  981.  
  982.                 RememberSpill();
  983.             }
  984.         }
  985.  
  986.         if(WriteRequest)
  987.         {
  988.             STATIC UBYTE __far TranslateData[512];
  989.  
  990.                 /* xpr wants to see the data before it is
  991.                  * transferred.
  992.                  */
  993.  
  994.             if(XProtocolBase && (TransferBits & XPRS_USERMON))
  995.             {
  996.                 if(Size = XProtocolUserMon(XprIO,Buffer,Size,Size))
  997.                 {
  998.                     if(SendTable)
  999.                     {
  1000.                         struct TranslationHandle Handle;
  1001.  
  1002.                             /* Set up for buffer translation. */
  1003.  
  1004.                         TranslateSetup(&Handle,Buffer,Size,TranslateData,512,SendTable);
  1005.  
  1006.                             /* Full or half duplex? */
  1007.  
  1008.                         if(Config -> SerialConfig -> Duplex == DUPLEX_FULL)
  1009.                         {
  1010.                             if(SerWriteBypass)
  1011.                             {
  1012.                                     /* Process the data... */
  1013.  
  1014.                                 while(Size = TranslateBuffer(&Handle))
  1015.                                 {
  1016.                                     if((*SerWriteBypass)(TranslateData,Size))
  1017.                                     {
  1018.                                         WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1019.                                         WriteRequest -> IOSer . io_Data        = TranslateData;
  1020.                                         WriteRequest -> IOSer . io_Length    = Size;
  1021.  
  1022.                                             /* ...and send it. */
  1023.  
  1024.                                         DoIO(WriteRequest);
  1025.                                     }
  1026.  
  1027.                                     BytesOut += Size;
  1028.                                 }
  1029.                             }
  1030.                             else
  1031.                             {
  1032.                                     /* Process the data... */
  1033.  
  1034.                                 while(Size = TranslateBuffer(&Handle))
  1035.                                 {
  1036.                                     WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1037.                                     WriteRequest -> IOSer . io_Data        = TranslateData;
  1038.                                     WriteRequest -> IOSer . io_Length    = Size;
  1039.  
  1040.                                         /* ...and send it. */
  1041.  
  1042.                                     DoIO(WriteRequest);
  1043.  
  1044.                                     BytesOut += Size;
  1045.                                 }
  1046.                             }
  1047.                         }
  1048.                         else
  1049.                         {
  1050.                             if(Marking)
  1051.                                 DropMarker();
  1052.  
  1053.                             if(SerWriteBypass)
  1054.                             {
  1055.                                 while(Size = TranslateBuffer(&Handle))
  1056.                                 {
  1057.                                     if((*SerWriteBypass)(TranslateData,Size))
  1058.                                     {
  1059.                                         WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1060.                                         WriteRequest -> IOSer . io_Data        = TranslateData;
  1061.                                         WriteRequest -> IOSer . io_Length    = Size;
  1062.  
  1063.                                             /* Process the data while it is transferred. */
  1064.  
  1065.                                         SendIO(WriteRequest);
  1066.  
  1067.                                         ConProcess(Buffer,Size);
  1068.  
  1069.                                         WaitIO(WriteRequest);
  1070.                                     }
  1071.  
  1072.                                     BytesOut += Size;
  1073.                                 }
  1074.                             }
  1075.                             else
  1076.                             {
  1077.                                 while(Size = TranslateBuffer(&Handle))
  1078.                                 {
  1079.                                     WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1080.                                     WriteRequest -> IOSer . io_Data        = TranslateData;
  1081.                                     WriteRequest -> IOSer . io_Length    = Size;
  1082.  
  1083.                                         /* Process the data while it is transferred. */
  1084.  
  1085.                                     SendIO(WriteRequest);
  1086.  
  1087.                                     ConProcess(Buffer,Size);
  1088.  
  1089.                                     WaitIO(WriteRequest);
  1090.  
  1091.                                     BytesOut += Size;
  1092.                                 }
  1093.                             }
  1094.                         }
  1095.                     }
  1096.                     else
  1097.                     {
  1098.                         if(SerWriteBypass)
  1099.                         {
  1100.                             if((*SerWriteBypass)(Buffer,Size))
  1101.                             {
  1102.                                 WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1103.                                 WriteRequest -> IOSer . io_Data        = Buffer;
  1104.                                 WriteRequest -> IOSer . io_Length    = Size;
  1105.  
  1106.                                     /* If full duplex is enabled, send the entire
  1107.                                      * buffer without processing.
  1108.                                      */
  1109.  
  1110.                                 if(Config -> SerialConfig -> Duplex == DUPLEX_FULL)
  1111.                                     DoIO(WriteRequest);
  1112.                                 else
  1113.                                 {
  1114.                                         /* Process the data while it is transferred. */
  1115.  
  1116.                                     SendIO(WriteRequest);
  1117.  
  1118.                                     if(Marking)
  1119.                                         DropMarker();
  1120.  
  1121.                                     ConProcess(Buffer,Size);
  1122.  
  1123.                                     WaitIO(WriteRequest);
  1124.                                 }
  1125.                             }
  1126.                             else
  1127.                             {
  1128.                                 if(Config -> SerialConfig -> Duplex != DUPLEX_FULL)
  1129.                                 {
  1130.                                     if(Marking)
  1131.                                         DropMarker();
  1132.  
  1133.                                     ConProcess(Buffer,Size);
  1134.                                 }
  1135.                             }
  1136.                         }
  1137.                         else
  1138.                         {
  1139.                             WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1140.                             WriteRequest -> IOSer . io_Data        = Buffer;
  1141.                             WriteRequest -> IOSer . io_Length    = Size;
  1142.  
  1143.                                 /* If full duplex is enabled, send the entire
  1144.                                  * buffer without processing.
  1145.                                  */
  1146.  
  1147.                             if(Config -> SerialConfig -> Duplex == DUPLEX_FULL)
  1148.                                 DoIO(WriteRequest);
  1149.                             else
  1150.                             {
  1151.                                     /* Process the data while it is transferred. */
  1152.  
  1153.                                 SendIO(WriteRequest);
  1154.  
  1155.                                 if(Marking)
  1156.                                     DropMarker();
  1157.  
  1158.                                 ConProcess(Buffer,Size);
  1159.  
  1160.                                 WaitIO(WriteRequest);
  1161.                             }
  1162.                         }
  1163.  
  1164.                         BytesOut += Size;
  1165.                     }
  1166.                 }
  1167.             }
  1168.             else
  1169.             {
  1170.                 if(SendTable)
  1171.                 {
  1172.                     struct TranslationHandle Handle;
  1173.  
  1174.                         /* Set up for buffer translation. */
  1175.  
  1176.                     TranslateSetup(&Handle,Buffer,Size,TranslateData,512,SendTable);
  1177.  
  1178.                         /* Full or half duplex? */
  1179.  
  1180.                     if(Config -> SerialConfig -> Duplex == DUPLEX_FULL)
  1181.                     {
  1182.                         if(SerWriteBypass)
  1183.                         {
  1184.                                 /* Process the data... */
  1185.  
  1186.                             while(Size = TranslateBuffer(&Handle))
  1187.                             {
  1188.                                 if((*SerWriteBypass)(TranslateData,Size))
  1189.                                 {
  1190.                                     WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1191.                                     WriteRequest -> IOSer . io_Data        = TranslateData;
  1192.                                     WriteRequest -> IOSer . io_Length    = Size;
  1193.  
  1194.                                         /* ...and send it. */
  1195.  
  1196.                                     DoIO(WriteRequest);
  1197.                                 }
  1198.  
  1199.                                 BytesOut += Size;
  1200.                             }
  1201.                         }
  1202.                         else
  1203.                         {
  1204.                                 /* Process the data... */
  1205.  
  1206.                             while(Size = TranslateBuffer(&Handle))
  1207.                             {
  1208.                                 WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1209.                                 WriteRequest -> IOSer . io_Data        = TranslateData;
  1210.                                 WriteRequest -> IOSer . io_Length    = Size;
  1211.  
  1212.                                     /* ...and send it. */
  1213.  
  1214.                                 DoIO(WriteRequest);
  1215.  
  1216.                                 BytesOut += Size;
  1217.                             }
  1218.                         }
  1219.                     }
  1220.                     else
  1221.                     {
  1222.                         if(Marking)
  1223.                             DropMarker();
  1224.  
  1225.                         if(SerWriteBypass)
  1226.                         {
  1227.                             while(Size = TranslateBuffer(&Handle))
  1228.                             {
  1229.                                 if((*SerWriteBypass)(TranslateData,Size))
  1230.                                 {
  1231.                                     WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1232.                                     WriteRequest -> IOSer . io_Data        = TranslateData;
  1233.                                     WriteRequest -> IOSer . io_Length    = Size;
  1234.  
  1235.                                         /* Process the data while it is transferred. */
  1236.  
  1237.                                     SendIO(WriteRequest);
  1238.  
  1239.                                     ConProcess(Buffer,Size);
  1240.  
  1241.                                     WaitIO(WriteRequest);
  1242.                                 }
  1243.  
  1244.                                 BytesOut += Size;
  1245.                             }
  1246.                         }
  1247.                         else
  1248.                         {
  1249.                             while(Size = TranslateBuffer(&Handle))
  1250.                             {
  1251.                                 WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1252.                                 WriteRequest -> IOSer . io_Data        = TranslateData;
  1253.                                 WriteRequest -> IOSer . io_Length    = Size;
  1254.  
  1255.                                     /* Process the data while it is transferred. */
  1256.  
  1257.                                 SendIO(WriteRequest);
  1258.  
  1259.                                 ConProcess(Buffer,Size);
  1260.  
  1261.                                 WaitIO(WriteRequest);
  1262.  
  1263.                                 BytesOut += Size;
  1264.                             }
  1265.                         }
  1266.                     }
  1267.                 }
  1268.                 else
  1269.                 {
  1270.                     if(SerWriteBypass)
  1271.                     {
  1272.                         if((*SerWriteBypass)(Buffer,Size))
  1273.                         {
  1274.                             WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1275.                             WriteRequest -> IOSer . io_Data        = Buffer;
  1276.                             WriteRequest -> IOSer . io_Length    = Size;
  1277.  
  1278.                                 /* If full duplex is enabled, send the entire
  1279.                                  * buffer without processing.
  1280.                                  */
  1281.  
  1282.                             if(Config -> SerialConfig -> Duplex == DUPLEX_FULL)
  1283.                                 DoIO(WriteRequest);
  1284.                             else
  1285.                             {
  1286.                                     /* Process the data while it is transferred. */
  1287.  
  1288.                                 SendIO(WriteRequest);
  1289.  
  1290.                                 if(Marking)
  1291.                                     DropMarker();
  1292.  
  1293.                                 ConProcess(Buffer,Size);
  1294.  
  1295.                                 WaitIO(WriteRequest);
  1296.                             }
  1297.                         }
  1298.                     }
  1299.                     else
  1300.                     {
  1301.                         WriteRequest -> IOSer . io_Command    = CMD_WRITE;
  1302.                         WriteRequest -> IOSer . io_Data        = Buffer;
  1303.                         WriteRequest -> IOSer . io_Length    = Size;
  1304.  
  1305.                             /* If full duplex is enabled, send the entire
  1306.                              * buffer without processing.
  1307.                              */
  1308.  
  1309.                         if(Config -> SerialConfig -> Duplex == DUPLEX_FULL)
  1310.                             DoIO(WriteRequest);
  1311.                         else
  1312.                         {
  1313.                                 /* Process the data while it is transferred. */
  1314.  
  1315.                             SendIO(WriteRequest);
  1316.  
  1317.                             if(Marking)
  1318.                                 DropMarker();
  1319.  
  1320.                             ConProcess(Buffer,Size);
  1321.  
  1322.                             WaitIO(WriteRequest);
  1323.                         }
  1324.                     }
  1325.  
  1326.                     BytesOut += Size;
  1327.                 }
  1328.             }
  1329.         }
  1330.     }
  1331. }
  1332.  
  1333.     /* RestartSerial():
  1334.      *
  1335.      *    Restart read/write activity on the serial line.
  1336.      */
  1337.  
  1338. VOID __regargs
  1339. RestartSerial(BYTE Override)
  1340. {
  1341.     if(ReadRequest)
  1342.     {
  1343.         ReadRequest -> IOSer . io_Command    = CMD_READ;
  1344.         ReadRequest -> IOSer . io_Data        = ReadBuffer;
  1345.         ReadRequest -> IOSer . io_Length     = 1;
  1346.  
  1347.         ClrSignal(SIG_SERIAL);
  1348.  
  1349.         SendIO(ReadRequest);
  1350.     }
  1351. }
  1352.  
  1353.     /* ClearSerial():
  1354.      *
  1355.      *    Terminate all read/write activity on the serial line.
  1356.      */
  1357.  
  1358. VOID
  1359. ClearSerial()
  1360. {
  1361.     if(ReadRequest)
  1362.     {
  1363.         if(!CheckIO(ReadRequest))
  1364.             AbortIO(ReadRequest);
  1365.  
  1366.         WaitIO(ReadRequest);
  1367.     }
  1368.  
  1369.     if(WriteRequest)
  1370.     {
  1371.         WriteRequest -> IOSer . io_Command = CMD_FLUSH;
  1372.  
  1373.         DoIO(WriteRequest);
  1374.  
  1375.         WriteRequest -> IOSer . io_Command = CMD_CLEAR;
  1376.  
  1377.         DoIO(WriteRequest);
  1378.     }
  1379. }
  1380.  
  1381.     /* DropDTR():
  1382.      *
  1383.      *    Drop the data terminal ready signal (i.e. close, wait a bit
  1384.      *    and then reopen the serial drive).
  1385.      */
  1386.  
  1387. BYTE
  1388. DropDTR()
  1389. {
  1390.         /* Finish all serial read activity. */
  1391.  
  1392.     ClearSerial();
  1393.  
  1394.         /* Do we have any channels to work with? */
  1395.  
  1396.     if(ReadRequest && WriteRequest)
  1397.     {
  1398.             /* Close the device. */
  1399.  
  1400.         CloseDevice(ReadRequest);
  1401.  
  1402.             /* Wait a bit. */
  1403.  
  1404.         WaitTime(1,0);
  1405.  
  1406.             /* Set up the original configuration data. */
  1407.  
  1408.         SetFlags(ReadRequest);
  1409.  
  1410.         ReadRequest -> io_RBufLen = Config -> SerialConfig -> SerialBufferSize;
  1411.  
  1412.             /* Reopen the driver. */
  1413.  
  1414.         if(!OpenDevice(Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber,ReadRequest,0))
  1415.         {
  1416.             struct MsgPort *WritePort = WriteRequest -> IOSer . io_Message . mn_ReplyPort;
  1417.  
  1418.                 /* Fill in the rest. */
  1419.  
  1420.             CopyMem(ReadRequest,WriteRequest,sizeof(struct IOExtSer));
  1421.  
  1422.             WriteRequest -> IOSer . io_Message . mn_ReplyPort = WritePort;
  1423.  
  1424.             WriteRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
  1425.  
  1426.             SetFlags(WriteRequest);
  1427.  
  1428.             DoIO(WriteRequest);
  1429.  
  1430.                 /* Restart read activity. */
  1431.  
  1432.             RestartSerial(FALSE);
  1433.  
  1434.             return(TRUE);
  1435.         }
  1436.         else
  1437.             DeleteSerial();
  1438.     }
  1439.     else
  1440.     {
  1441.         DeleteSerial();
  1442.  
  1443.         return(TRUE);
  1444.     }
  1445.  
  1446.     return(FALSE);
  1447. }
  1448.  
  1449.     /* DeleteSerial():
  1450.      *
  1451.      *    Close the serial device and release all associated
  1452.      *    resources.
  1453.      */
  1454.  
  1455. VOID
  1456. DeleteSerial()
  1457. {
  1458.     BYTE Closed = FALSE;
  1459.  
  1460.     if(ReadRequest)
  1461.     {
  1462.         if(ReadRequest -> IOSer . io_Device)
  1463.         {
  1464.             struct Device    *Device;
  1465.             UBYTE         Name[MAX_FILENAME_LENGTH];
  1466.  
  1467.             if(!Config -> SerialConfig -> Shared)
  1468.             {
  1469.                 ReadRequest -> IOSer . io_Command = CMD_RESET;
  1470.  
  1471.                 DoIO(ReadRequest);
  1472.             }
  1473.  
  1474.             strcpy(Name,ReadRequest -> IOSer . io_Device -> dd_Library . lib_Node . ln_Name);
  1475.  
  1476.             CloseDevice(ReadRequest);
  1477.  
  1478.             Forbid();
  1479.  
  1480.             if(Device = (struct Device *)FindName(&SysBase -> DeviceList,Name))
  1481.                 RemDevice(Device);
  1482.  
  1483.             Permit();
  1484.  
  1485.             Closed = TRUE;
  1486.         }
  1487.  
  1488.         DeleteIORequest(ReadRequest);
  1489.  
  1490.         ReadRequest = NULL;
  1491.     }
  1492.  
  1493.     if(WriteRequest)
  1494.     {
  1495.         if(WriteRequest -> IOSer . io_Device && !Closed)
  1496.         {
  1497.             struct Device    *Device;
  1498.             UBYTE         Name[MAX_FILENAME_LENGTH];
  1499.  
  1500.             if(!Config -> SerialConfig -> Shared && ReadRequest)
  1501.             {
  1502.                 ReadRequest -> IOSer . io_Command = CMD_RESET;
  1503.  
  1504.                 DoIO(ReadRequest);
  1505.             }
  1506.  
  1507.             strcpy(Name,WriteRequest -> IOSer . io_Device -> dd_Library . lib_Node . ln_Name);
  1508.  
  1509.             CloseDevice(WriteRequest);
  1510.  
  1511.             Forbid();
  1512.  
  1513.             if(Device = (struct Device *)FindName(&SysBase -> DeviceList,Name))
  1514.                 RemDevice(Device);
  1515.  
  1516.             Permit();
  1517.         }
  1518.  
  1519.         if(WriteRequest -> IOSer . io_Message . mn_ReplyPort)
  1520.             DeleteMsgPort(WriteRequest -> IOSer . io_Message . mn_ReplyPort);
  1521.  
  1522.         DeleteIORequest(WriteRequest);
  1523.  
  1524.         WriteRequest = NULL;
  1525.     }
  1526.  
  1527.     if(ReadPort)
  1528.     {
  1529.         DeleteMsgPort(ReadPort);
  1530.  
  1531.         ReadPort = NULL;
  1532.     }
  1533.  
  1534.     if(ReadBuffer)
  1535.     {
  1536.         FreeVecPooled(ReadBuffer);
  1537.  
  1538.         ReadBuffer = NULL;
  1539.     }
  1540.  
  1541.     if(HostReadBuffer)
  1542.     {
  1543.         FreeVecPooled(HostReadBuffer);
  1544.  
  1545.         HostReadBuffer = NULL;
  1546.     }
  1547.  
  1548.     if(StripBuffer)
  1549.     {
  1550.         FreeVecPooled(StripBuffer);
  1551.  
  1552.         StripBuffer = NULL;
  1553.     }
  1554.  
  1555.     if(OwnDevUnitBase && SerialDevice[0] && UnitNumber != -1 && SerialLocked)
  1556.     {
  1557.         FreeDevUnit(SerialDevice,UnitNumber);
  1558.  
  1559.         SerialDevice[0] = 0;
  1560.  
  1561.         UnitNumber = -1;
  1562.     }
  1563.  
  1564.     if(OwnDevBit != -1)
  1565.     {
  1566.         FreeSignal(OwnDevBit);
  1567.  
  1568.         OwnDevBit = -1;
  1569.     }
  1570.  
  1571.     SerialLocked = FALSE;
  1572. }
  1573.  
  1574.     /* GetSerialError(LONG Error,BYTE *Reset):
  1575.      *
  1576.      *    Return an error message for each possible serial device error.
  1577.      */
  1578.  
  1579. STRPTR __regargs
  1580. GetSerialError(LONG Error,BYTE *Reset)
  1581. {
  1582.     if(Reset)
  1583.         *Reset = FALSE;
  1584.  
  1585.     switch(Error)
  1586.     {
  1587.         case IOERR_BADLENGTH:
  1588.         case IOERR_BADADDRESS:
  1589.         case IOERR_SELFTEST:
  1590.         case IOERR_OPENFAIL:
  1591.  
  1592.             return(LocaleString(MSG_SERIAL_OPENFAILURE_TXT));
  1593.  
  1594.         case SerErr_DevBusy:
  1595.  
  1596.             return(LocaleString(MSG_SERIAL_ERROR_DEVBUSY_TXT));
  1597.  
  1598.         case SerErr_BaudMismatch:
  1599.  
  1600.             if(Reset)
  1601.                 *Reset = TRUE;
  1602.  
  1603.             return(LocaleString(MSG_SERIAL_ERROR_BAUDMISMATCH_TXT));
  1604.  
  1605.         case SerErr_BufErr:
  1606.  
  1607.             if(Reset)
  1608.                 *Reset = TRUE;
  1609.  
  1610.             return(LocaleString(MSG_SERIAL_ERROR_BUFERR_TXT));
  1611.  
  1612.         case SerErr_InvParam:
  1613.  
  1614.             if(Reset)
  1615.                 *Reset = TRUE;
  1616.  
  1617.             return(LocaleString(MSG_SERIAL_ERROR_INVPARAM_TXT));
  1618.  
  1619.         case SerErr_LineErr:
  1620.  
  1621.             return(LocaleString(MSG_SERIAL_ERROR_LINEERR_TXT));
  1622.  
  1623.         case SerErr_ParityErr:
  1624.  
  1625.             if(Reset)
  1626.                 *Reset = TRUE;
  1627.  
  1628.             return(LocaleString(MSG_SERIAL_ERROR_PARITYERR_TXT));
  1629.  
  1630.         case SerErr_TimerErr:
  1631.  
  1632.             return(LocaleString(MSG_SERIAL_ERROR_TIMERERR_TXT));
  1633.  
  1634.         case SerErr_BufOverflow:
  1635.  
  1636.             if(Reset)
  1637.                 *Reset = TRUE;
  1638.  
  1639.             return(LocaleString(MSG_SERIAL_ERROR_BUFOVERFLOW_TXT));
  1640.  
  1641.         case SerErr_NoDSR:
  1642.  
  1643.             return(LocaleString(MSG_SERIAL_ERROR_NODSR_TXT));
  1644.  
  1645.     /*    case SerErr_UnitBusy:    */
  1646.         case IOERR_UNITBUSY:
  1647.         case 16:
  1648.  
  1649.             return(LocaleString(MSG_SERIAL_ERROR_UNIT_BUSY_TXT));
  1650.  
  1651.         default:
  1652.  
  1653.             return(NULL);
  1654.     }
  1655. }
  1656.  
  1657.     /* CreateSerial():
  1658.      *
  1659.      *    Create handles for the serial device and open it.
  1660.      */
  1661.  
  1662. STRPTR
  1663. CreateSerial()
  1664. {
  1665.     struct MsgPort *WritePort;
  1666.  
  1667.         /* If OwnDevUnit.library is available, try to lock
  1668.          * the serial driver.
  1669.          */
  1670.  
  1671. Start:    if(OwnDevUnitBase && Config -> SerialConfig -> UseOwnDevUnit)
  1672.     {
  1673.         STRPTR Error;
  1674.  
  1675.             /* Allocate a signal for OwnDevUnit, in case we might need it. */
  1676.  
  1677.         OwnDevBit = AllocSignal(-1);
  1678.  
  1679.             /* Attempt to lock the device unit... */
  1680.  
  1681.         if(Error = AttemptDevUnit(Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber,TermIDString,OwnDevBit == -1 ? NULL : OwnDevBit))
  1682.         {
  1683.                 /* Check for error type if any. */
  1684.  
  1685.             if(!Strnicmp(Error,ODUERR_LEADCHAR,1))
  1686.                 SPrintf(SharedBuffer,LocaleString(MSG_SERIAL_ERROR_ACCESSING_TXT),Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber,&Error[1]);
  1687.             else
  1688.                 SPrintf(SharedBuffer,LocaleString(MSG_SERIAL_DEVICE_IN_USE_TXT),Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber,Error);
  1689.  
  1690.             SerialDevice[0] = 0;
  1691.  
  1692.             UnitNumber = -1;
  1693.  
  1694.             SerialLocked = FALSE;
  1695.  
  1696.             return(SharedBuffer);
  1697.         }
  1698.         else
  1699.         {
  1700.             strcpy(SerialDevice,Config -> SerialConfig -> SerialDevice);
  1701.  
  1702.             UnitNumber = Config -> SerialConfig -> UnitNumber;
  1703.  
  1704.             SerialLocked = TRUE;
  1705.         }
  1706.     }
  1707.     else
  1708.         SerialLocked = FALSE;
  1709.  
  1710.     if(ReadBuffer = AllocVecPooled(Config -> SerialConfig -> SerialBufferSize,MEMF_ANY))
  1711.     {
  1712.         if(StripBuffer = AllocVecPooled(Config -> SerialConfig -> SerialBufferSize,MEMF_ANY))
  1713.         {
  1714.             if(XProtocolBase && (TransferBits & XPRS_HOSTNOWAIT))
  1715.                 HostReadBuffer = AllocVecPooled(Config -> SerialConfig -> SerialBufferSize,MEMF_ANY);
  1716.             else
  1717.                 HostReadBuffer = NULL;
  1718.  
  1719.             if(ReadPort = (struct MsgPort *)CreateMsgPort())
  1720.             {
  1721.                 if(ReadRequest = (struct IOExtSer *)CreateIORequest(ReadPort,sizeof(struct IOExtSer)))
  1722.                 {
  1723.                     LONG Error;
  1724.  
  1725.                     SetFlags(ReadRequest);
  1726.  
  1727.                     if(!(Error = OpenDevice(Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber,ReadRequest,0)))
  1728.                     {
  1729.                         if(WritePort = (struct MsgPort *)CreateMsgPort())
  1730.                         {
  1731.                             if(WriteRequest = (struct IOExtSer *)CreateIORequest(WritePort,sizeof(struct IOExtSer)))
  1732.                             {
  1733.                                 CopyMem(ReadRequest,WriteRequest,sizeof(struct IOExtSer));
  1734.  
  1735.                                 WriteRequest -> IOSer . io_Message . mn_ReplyPort = WritePort;
  1736.  
  1737.                                 WriteRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
  1738.                                 SetFlags(WriteRequest);
  1739.                                 DoIO(WriteRequest);
  1740.  
  1741.                                 ReadRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
  1742.                                 SetFlags(ReadRequest);
  1743.                                 DoIO(ReadRequest);
  1744.  
  1745.                                 /* If RTS/CTS (7 wire handshaking) is
  1746.                                  * selected, have a look at the DSR
  1747.                                  * line to see whether the modem
  1748.                                  * connected is willing to support
  1749.                                  * this handshaking mode.
  1750.                                  */
  1751.  
  1752.                                 if(Config -> SerialConfig -> HandshakingProtocol == HANDSHAKING_RTSCTS_DSR)
  1753.                                 {
  1754. Retry:                                    WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  1755.  
  1756.                                     DoIO(WriteRequest);
  1757.  
  1758.                                         /* If the line happens to
  1759.                                          * be high, there is no
  1760.                                          * DSR signal present.
  1761.                                          */
  1762.  
  1763.                                     if(WriteRequest -> io_Status & CIAF_COMDSR)
  1764.                                     {
  1765.                                         if(MyEasyRequest(Window,LocaleString(MSG_SERIAL_NO_DSR_SIGNAL_TXT),LocaleString(MSG_SERIAL_RETRY_CANCEL_TXT)))
  1766.                                             goto Retry;
  1767.                                         else
  1768.                                         {
  1769.                                             DeleteSerial();
  1770.  
  1771.                                             Config -> SerialConfig -> HandshakingProtocol = HANDSHAKING_NONE;
  1772.  
  1773.                                             SerialMessage = LocaleString(MSG_SERIAL_NO_DSR_SIGNAL_HANDSHAKING_DISABLED_TXT);
  1774.  
  1775.                                             goto Start;
  1776.                                         }
  1777.                                     }
  1778.                                 }
  1779.  
  1780.                                 RestartSerial(FALSE);
  1781.  
  1782.                                 return(NULL);
  1783.                             }
  1784.                         }
  1785.                         else
  1786.                         {
  1787.                             SerialMessage = NULL;
  1788.  
  1789.                             DeleteSerial();
  1790.  
  1791.                             return(LocaleString(MSG_SERIAL_FAILED_TO_CREATE_WRITE_PORT_TXT));
  1792.                         }
  1793.                     }
  1794.                     else
  1795.                     {
  1796.                         STRPTR String;
  1797.  
  1798.                         ReadRequest -> IOSer . io_Device = NULL;
  1799.  
  1800.                         DeleteSerial();
  1801.  
  1802.                         SerialMessage = NULL;
  1803.  
  1804.                         if(!(String = GetSerialError(Error,NULL)))
  1805.                             String = LocaleString(MSG_SERIAL_ERROR_DEVBUSY_TXT);
  1806.  
  1807.                         SPrintf(SharedBuffer,String,Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber);
  1808.  
  1809.                         return(SharedBuffer);
  1810.                     }
  1811.                 }
  1812.             }
  1813.             else
  1814.             {
  1815.                 SerialMessage = NULL;
  1816.  
  1817.                 DeleteSerial();
  1818.  
  1819.                 return(LocaleString(MSG_SERIAL_FAILED_TO_CREATE_READ_PORT_TXT));
  1820.             }
  1821.         }
  1822.     }
  1823.  
  1824.     SerialMessage = NULL;
  1825.  
  1826.     DeleteSerial();
  1827.  
  1828.     return(LocaleString(MSG_SERIAL_NOT_ENOUGH_MEMORY_TXT));
  1829. }
  1830.  
  1831.     /* ReconfigureSerial(struct Window *Window,struct SerialSettings *SerialConfig):
  1832.      *
  1833.      *    Reconfigure the serial driver according to the new
  1834.      *    serial settings.
  1835.      */
  1836.  
  1837. BYTE __regargs
  1838. ReconfigureSerial(struct Window *Window,struct SerialSettings *SerialConfig)
  1839. {
  1840.     BYTE    Success    = RECONFIGURE_NOCHANGE,
  1841.         IsNew;
  1842.  
  1843.         /* Are new settings to be installed or have they already
  1844.          * been copied to the correct locations?
  1845.          */
  1846.  
  1847.     if(SerialConfig)
  1848.     {
  1849.         if(memcmp(Config -> SerialConfig,SerialConfig,sizeof(struct SerialSettings)))
  1850.             IsNew = TRUE;
  1851.         else
  1852.             IsNew = FALSE;
  1853.     }
  1854.     else
  1855.     {
  1856.         if(memcmp(Config -> SerialConfig,PrivateConfig -> SerialConfig,sizeof(struct SerialSettings)))
  1857.             IsNew = TRUE;
  1858.         else
  1859.             IsNew = FALSE;
  1860.     }
  1861.  
  1862.         /* Any changes in the serial configuration area? */
  1863.  
  1864.     if(IsNew)
  1865.     {
  1866.         BYTE SameDevice = TRUE;
  1867.  
  1868.             /* Any new data to swap in? */
  1869.  
  1870.         if(SerialConfig)
  1871.         {
  1872.                 /* Store the previous settings. */
  1873.  
  1874.             SaveConfig(Config,PrivateConfig);
  1875.  
  1876.                 /* Install the new settings. */
  1877.  
  1878.             memcpy(Config -> SerialConfig,SerialConfig,sizeof(struct SerialSettings));
  1879.         }
  1880.  
  1881.             /* Any device name or unit number change? */
  1882.  
  1883.         if(strcmp(PrivateConfig -> SerialConfig -> SerialDevice,Config -> SerialConfig -> SerialDevice) || PrivateConfig -> SerialConfig -> UnitNumber != Config -> SerialConfig -> UnitNumber || PrivateConfig -> SerialConfig -> UseOwnDevUnit != Config -> SerialConfig -> UseOwnDevUnit)
  1884.             SameDevice = FALSE;
  1885.         else
  1886.         {
  1887.                 /* Handshaking mode changed to RTS/CTS protocol? */
  1888.  
  1889.             if((PrivateConfig -> SerialConfig -> HandshakingProtocol == HANDSHAKING_NONE && Config -> SerialConfig -> HandshakingProtocol != HANDSHAKING_NONE) || (PrivateConfig -> SerialConfig -> HandshakingProtocol != HANDSHAKING_NONE && Config -> SerialConfig -> HandshakingProtocol == HANDSHAKING_NONE))
  1890.                 SameDevice = FALSE;
  1891.         }
  1892.  
  1893.             /* Stop any IO activity. */
  1894.  
  1895.         if(ReadRequest)
  1896.             ClearSerial();
  1897.         else
  1898.             SameDevice = FALSE;
  1899.  
  1900.             /* No dramatic changes? Simply change the parameters. */
  1901.  
  1902.         if(SameDevice)
  1903.         {
  1904.             LONG Error;
  1905.  
  1906.             if(PrivateConfig -> SerialConfig -> SerialBufferSize != Config -> SerialConfig -> SerialBufferSize)
  1907.             {
  1908.                 STRPTR NewReadBuffer;
  1909.  
  1910.                 if(NewReadBuffer = AllocVecPooled(Config -> SerialConfig -> SerialBufferSize,MEMF_ANY))
  1911.                 {
  1912.                     STRPTR NewStripBuffer;
  1913.  
  1914.                     if(NewStripBuffer = AllocVecPooled(Config -> SerialConfig -> SerialBufferSize,MEMF_ANY))
  1915.                     {
  1916.                         FreeVecPooled(ReadBuffer);
  1917.                         FreeVecPooled(StripBuffer);
  1918.  
  1919.                         ReadBuffer    = NewReadBuffer;
  1920.                         StripBuffer    = NewStripBuffer;
  1921.                     }
  1922.                     else
  1923.                     {
  1924.                         FreeVecPooled(NewReadBuffer);
  1925.  
  1926.                         Config -> SerialConfig -> SerialBufferSize = PrivateConfig -> SerialConfig -> SerialBufferSize;
  1927.                     }
  1928.                 }
  1929.                 else
  1930.                     Config -> SerialConfig -> SerialBufferSize = PrivateConfig -> SerialConfig -> SerialBufferSize;
  1931.             }
  1932.  
  1933.                 /* Use new parameters... */
  1934.  
  1935.             SetFlags(WriteRequest);
  1936.             SetFlags(ReadRequest);
  1937.  
  1938.                 /* ...and set them. */
  1939.  
  1940.             WriteRequest -> IOSer . io_Command    = SDCMD_SETPARAMS;
  1941.             ReadRequest -> IOSer . io_Command    = SDCMD_SETPARAMS;
  1942.  
  1943.             if(!(Error = DoIO(WriteRequest)))
  1944.                 Error = DoIO(ReadRequest);
  1945.  
  1946.                 /* Trouble? */
  1947.  
  1948.             if(Error)
  1949.             {
  1950.                 STRPTR    String;
  1951.                 BYTE    Reset;
  1952.  
  1953.                     /* Query the error message. */
  1954.  
  1955.                 if(!(String = GetSerialError(Error,&Reset)))
  1956.                     String = LocaleString(MSG_SERIAL_ERROR_DEVBUSY_TXT);
  1957.  
  1958.                     /* Build the device name/unit number string. */
  1959.  
  1960.                 SPrintf(SharedBuffer,String,Config -> SerialConfig -> SerialDevice,Config -> SerialConfig -> UnitNumber);
  1961.  
  1962.                     /* Display the error requester. */
  1963.  
  1964.                 LT_LockWindow(Window);
  1965.  
  1966.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SharedBuffer);
  1967.  
  1968.                 LT_UnlockWindow(Window);
  1969.  
  1970.                     /* Is a serial driver reset required? */
  1971.  
  1972.                 if(Reset)
  1973.                 {
  1974.                         /* Execute the reset command. */
  1975.  
  1976.                     WriteRequest -> IOSer . io_Command = CMD_RESET;
  1977.  
  1978.                     DoIO(WriteRequest);
  1979.  
  1980.                         /* Copy the serial driver settings
  1981.                          * to the global configuration.
  1982.                          */
  1983.  
  1984.                     GetFlags(Config,WriteRequest);
  1985.  
  1986.                         /* Also set the read request driver
  1987.                          * flags.
  1988.                          */
  1989.  
  1990.                     SetFlags(ReadRequest);
  1991.  
  1992.                     ReadRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
  1993.  
  1994.                     DoIO(ReadRequest);
  1995.                 }
  1996.             }
  1997.  
  1998.                 /* Restart read request. */
  1999.  
  2000.             RestartSerial(FALSE);
  2001.         }
  2002.         else
  2003.         {
  2004.             STRPTR Error;
  2005.  
  2006.                 /* Shut down the serial driver. */
  2007.  
  2008.             DeleteSerial();
  2009.  
  2010.                 /* Reinitialize the serial driver. */
  2011.  
  2012.             if(!(Error = CreateSerial()))
  2013.             {
  2014.                     /* Free the work buffer. */
  2015.  
  2016.                 if(StripBuffer)
  2017.                     FreeVecPooled(StripBuffer);
  2018.  
  2019.                     /* Try to allocate a new serial data work buffer. */
  2020.  
  2021.                 if(!(StripBuffer = (STRPTR)AllocVecPooled(Config -> SerialConfig -> SerialBufferSize,MEMF_ANY)))
  2022.                     Error = LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT);
  2023.             }
  2024.  
  2025.                 /* Trouble? */
  2026.  
  2027.             if(Error)
  2028.             {
  2029.                     /* Display the error requester. */
  2030.  
  2031.                 LT_LockWindow(Window);
  2032.  
  2033.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  2034.  
  2035.                     /* Clean up the mess :-( */
  2036.  
  2037.                 DeleteSerial();
  2038.  
  2039.                 LT_UnlockWindow(Window);
  2040.  
  2041.                 Success = RECONFIGURE_FAILURE;
  2042.             }
  2043.             else
  2044.             {
  2045.                     /* Are we to display an error message? */
  2046.  
  2047.                 if(SerialMessage)
  2048.                 {
  2049.                     MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  2050.  
  2051.                     SerialMessage = NULL;
  2052.                 }
  2053.             }
  2054.         }
  2055.     }
  2056.  
  2057.     return(Success);
  2058. }
  2059.  
  2060.     /* ReopenSerial():
  2061.      *
  2062.      *    Reopen the serial driver.
  2063.      */
  2064.  
  2065. VOID
  2066. ReopenSerial()
  2067. {
  2068.     BYTE    SerialClosed = TRUE;
  2069.     STRPTR    Error;
  2070.  
  2071.     do
  2072.     {
  2073.         if(Error = CreateSerial())
  2074.         {
  2075.             DeleteSerial();
  2076.  
  2077.             switch(MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_TERMMAIN_RETRY_IGNORE_QUIT_TXT),Error))
  2078.             {
  2079.                 case 2:    SerialClosed = FALSE;
  2080.                     break;
  2081.  
  2082.                 case 0:    MainTerminated = TRUE;
  2083.                     break;
  2084.             }
  2085.         }
  2086.         else
  2087.         {
  2088.             SerialClosed = FALSE;
  2089.  
  2090.             if(SerialMessage)
  2091.             {
  2092.                 MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  2093.  
  2094.                 SerialMessage = NULL;
  2095.             }
  2096.         }
  2097.     }
  2098.     while(SerialClosed);
  2099. }
  2100.  
  2101.     /* HandleSerial():
  2102.      *
  2103.      *    Handle the data coming in from the serial line.
  2104.      */
  2105.  
  2106. BYTE
  2107. HandleSerial()
  2108. {
  2109.     BYTE MoreData = FALSE;
  2110.  
  2111.     if(ReadPort && !ReleaseSerial && Status != STATUS_HOLDING)
  2112.     {
  2113.         if(HostReadBuffer)
  2114.         {
  2115.             LONG Length = XProtocolHostMon(XprIO,HostReadBuffer,0,Config -> SerialConfig -> SerialBufferSize);
  2116.  
  2117.             if(Length)
  2118.             {
  2119.                 if(Marking)
  2120.                     DropMarker();
  2121.  
  2122.                 ConProcess(HostReadBuffer,Length);
  2123.  
  2124.                 if(Status == STATUS_HOLDING)
  2125.                     return(FALSE);
  2126.             }
  2127.  
  2128.             MoreData = TRUE;
  2129.         }
  2130.  
  2131.         if(DataHold)
  2132.         {
  2133.             register STRPTR    Data    = DataHold;
  2134.             register LONG    Size    = DataSize;
  2135.  
  2136.             DataHold = NULL;
  2137.  
  2138.             if(Marking)
  2139.                 DropMarker();
  2140.  
  2141.             (* ConTransfer)(Data,Size);
  2142.  
  2143.             MoreData = TRUE;
  2144.  
  2145.             RestartSerial(FALSE);
  2146.  
  2147.             return(MoreData);
  2148.         }
  2149.  
  2150.             /* Any news? */
  2151.  
  2152.         if(CheckIO(ReadRequest))
  2153.         {
  2154.             MoreData = TRUE;
  2155.  
  2156.             if(!WaitIO(ReadRequest))
  2157.             {
  2158.                 if(Marking)
  2159.                     DropMarker();
  2160.  
  2161.                 BytesIn++;
  2162.  
  2163.                 (* ConTransfer)(ReadBuffer,1);
  2164.  
  2165.                 if(Status != STATUS_HOLDING && !DataHold)
  2166.                 {
  2167.                     ULONG Length;
  2168.  
  2169.                         /* Check how many bytes are still in
  2170.                          * the serial buffer.
  2171.                          */
  2172.  
  2173.                     WriteRequest -> IOSer . io_Command = SDCMD_QUERY;
  2174.  
  2175.                     DoIO(WriteRequest);
  2176.  
  2177.                     if(Length = WriteRequest -> IOSer . io_Actual)
  2178.                     {
  2179.                         ULONG Max = Config -> SerialConfig -> SerialBufferSize;
  2180.  
  2181.                         if(Max > Config -> SerialConfig -> Quantum)
  2182.                             Max = Config -> SerialConfig -> Quantum;
  2183.  
  2184.                         if(Length > Max)
  2185.                             Length = Max;
  2186.  
  2187.                         ReadRequest -> IOSer . io_Command    = CMD_READ;
  2188.                         ReadRequest -> IOSer . io_Data        = ReadBuffer;
  2189.                         ReadRequest -> IOSer . io_Length    = Length;
  2190.  
  2191.                         if(!DoIO(ReadRequest))
  2192.                         {
  2193.                             BytesIn += Length;
  2194.  
  2195.                             (* ConTransfer)(ReadBuffer,Length);
  2196.                         }
  2197.                     }
  2198.                 }
  2199.             }
  2200.  
  2201.             if(DataHold)
  2202.                 ClrSignal(SIG_SERIAL);
  2203.             else
  2204.                 RestartSerial(FALSE);
  2205.         }
  2206.     }
  2207.  
  2208.     return(MoreData);
  2209. }
  2210.